import java.util.HashSet;
import java.util.Set;

public class A3 {
    public int lengthOfLongestSubstring(String s) {
        int length = s.length();

        if (length <= 1) {
            return length;
        }
        int ans = 0;
        Set<Character> occ = new HashSet<>();
        int tail = 0;

        for (int head = 0; head < length; head++) {
            if (head != 0) {
                // 左指针向右移动一格，移除一个字符
                occ.remove(s.charAt(head - 1));
            }

            while (tail < length && !occ.contains(s.charAt(tail))) {
                occ.add(s.charAt(tail));
                tail++;
            }

            ans = Math.max(ans, tail - head);

        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new A3().lengthOfLongestSubstring(""));
        System.out.println(new A3().lengthOfLongestSubstring("dvdf"));
        System.out.println(new A3().lengthOfLongestSubstring("123123"));
        System.out.println(new A3().lengthOfLongestSubstring("23455567890"));
    }
}
